//
//  FeedbackTypeView.m
//  CoachsBook
//
//  Created by huiyong li on 2022/9/1.
//

#import "FeedbackTypeView.h"
@interface FeedbackTypeView()
@property (nonatomic,strong) NSMutableArray *butarr;
@end
@implementation FeedbackTypeView
-(NSMutableArray *)butarr
{
    if (!_butarr) {
        _butarr = [NSMutableArray array];
    }
    return _butarr;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self CreateUI];
    }
    return self;
}
-(void)CreateUI{
 
    UIView *backV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, APPwidth, 245)];
    backV.backgroundColor = [UIColor whiteColor];
    [self addSubview:backV];
    
    UIView *myDataLineV = [[UIView alloc]initWithFrame:CGRectMake(15, 15, 3, 15)];
    myDataLineV.backgroundColor = rgba(22, 120, 255, 1);
    myDataLineV.layer.cornerRadius = 2;
    [backV addSubview:myDataLineV];
    UILabel *myDataLab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(myDataLineV.frame)+5, 15, 70, 15)];
    myDataLab.text = @"反馈类型";
    myDataLab.textColor = [UIColor blackColor];
    myDataLab.textAlignment = 0;
    myDataLab.font = kPingFangSemibold(16);
    [backV addSubview:myDataLab];
    
    
    UIView *butView = [[UIView alloc]initWithFrame:CGRectMake(16, CGRectGetMaxY(myDataLab.frame)+15, APPwidth-32, 195)];
    butView.backgroundColor = rgba(245, 245, 250, 1);
    butView.layer.cornerRadius = 8;
    butView.layer.masksToBounds = YES;
    [backV addSubview:butView];
    
    NSArray *ServicesArr = @[@"内容建议",@"网络问题",@"程序BUG",@"界面问题",@"功能建议",@"优化建议",@"投诉举报",@"其它问题"];
    CGFloat btnW = (APPwidth-72)/2;
    CGFloat btnH = 30;
    for (int i = 0; i < ServicesArr.count; i++) {
        NSInteger row = i/2;
        NSInteger col = i%2;
        CGFloat btnX = 10 + (btnW + 20 ) * col;
        CGFloat btnY = 15 + (btnH + 15 ) * row;
        
        UIButton *ServicesBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        ServicesBtn.frame = CGRectMake(btnX,btnY, btnW, btnH);
        [ServicesBtn setTitle:ServicesArr[i] forState:0];
        ServicesBtn.titleLabel.textAlignment = 1;
        ServicesBtn.layer.cornerRadius = 8;
        [ServicesBtn setImage:CoachsBookImageName(@"nochoice") forState:UIControlStateNormal];
        [ServicesBtn setImage:CoachsBookImageName(@"choice") forState:UIControlStateSelected];
        ServicesBtn.titleLabel.textAlignment = 1;
        ServicesBtn.titleLabel.font = kPingFangRegular(14);
        [ServicesBtn setTitleColor:[UIColor blackColor] forState:0];
        ServicesBtn.imageEdgeInsets = UIEdgeInsetsMake(4, 0, 0, 6);
        ServicesBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
        ServicesBtn.tag = i*100;
        [ServicesBtn addTarget:self action:@selector(ServicesBtnCheng:) forControlEvents:UIControlEventTouchUpInside];
        [butView addSubview:ServicesBtn];
        ServicesBtn.selected = NO;
        if (i == 0) {
            ServicesBtn.selected = YES;
        }
        [self.butarr addObject:ServicesBtn];
    }
    
    
}

-(void)ServicesBtnCheng:(UIButton *)but
{
    for (UIButton *ServicesBtn in self.butarr) {
        ServicesBtn.selected = NO;
        if (ServicesBtn.tag == but.tag) {
            ServicesBtn.selected = YES;
        }
    }
    
    if ([self.delegate respondsToSelector:@selector(ServicesBtnSelectedDelegate:WithTitle:)]) {
        [self.delegate ServicesBtnSelectedDelegate:but.tag WithTitle:but.titleLabel.text];
    }
}


@end
